//
//  AccurateVC.m
//  YaoHeAPP
//
//  Created by mac on 15/12/9.
//  Copyright © 2015年 mac. All rights reserved.
//
//**********************精确找货二级页面：钢卷、钢板、钢管、型材、铝材
//在此页面判断是那种类型，不同的类型加载
#import "AccurateVC.h"
#import "Controller.h"
#import "JSONKit.h"
#import "Masonry.h"
#import "SinglePicker.h"
#import "CityPicker.h"
#import "TypePicker.h"
#import "TypeClassPicker.h"
#import "ProducersPicker.h"
#import "TakingPicturesVC.h"
#import "IssueSuccess.h"
#import "MyCell.h"
#import "Tool.h"
#import "ProvinceAndCity.h"
#import "UIImageView+WebCache.h"
#import "UIImage+WebP.h"
#import "SurfacePicker.h"
#define font14 [UIFont systemFontOfSize:14]
#define font15 [UIFont systemFontOfSize:15]
#define font16 [UIFont systemFontOfSize:16]
@interface AccurateVC ()
{
    NSInteger width;
    NSInteger height;
    BOOL juan_cai;//卷材
    BOOL dai_cai; //带材
    BOOL ban__cai;//板材
    BOOL guan_cai;//管材
    BOOL xing_cai;//型材
    BOOL lv_cai;  //铝材
    UIFont*font_15;
    UITableViewCell*cell1;
    UIColor * gayColor;
    UICollectionView*_collectionView;
}
@end

@implementation AccurateVC

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"AccurateVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"AccurateVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    width=self.view.frame.size.width;
    height=self.view.frame.size.height;
    _cImages=[[NSMutableArray alloc]init];
   
    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(kNavigationBarHeight);  make.right.offset(0);
    }];
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=[NSString stringWithFormat:@"发布求购*%@",_typeString];
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(width/2-70);
        make.width.offset(150);
        make.height.offset(30);
    }];
    //返回按钮
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.bottom.offset(-12);
    }];
    
    //_imageArray=[[NSMutableArray alloc]init];
    //判断从哪个页面过跳过来的
    
    if ([_typeString isEqualToString:@"带"]||[_typeString isEqualToString:@"带材"]) {
        dai_cai =YES;
    }
    
    if ([_typeString isEqualToString:@"卷材"]||[_typeString isEqualToString:@"卷"]) {
        juan_cai =YES;
    }
    
    if ([_typeString isEqualToString:@"板材"]||[_typeString isEqualToString:@"板"]) {
        ban__cai =YES;
    }
    
    if ([_typeString isEqualToString:@"管材"]||[_typeString isEqualToString:@"管"]) {
        guan_cai =YES;
    }
    
    if ([_typeString isEqualToString:@"型材"]||[_typeString isEqualToString:@"型"]) {
        xing_cai =YES;
    }
    
    if ([_typeString isEqualToString:@"铝材"]||[_typeString isEqualToString:@"铝"]) {
        lv_cai=YES;
    }
    
    
    //字体
    font_15=[UIFont systemFontOfSize:15];
    //文字颜色
    gayColor=[UIColor grayColor];
    
#pragma mark--------------求购重新采购
    
    if ([self.pageString isEqualToString:@"求购重新采购"]) {
        //类别
        self.StrclassTypeL=_detailes.variety_name;
        self.classTypeN=[NSString stringWithFormat:@"%@", _detailes.variety_ID];//类别ID
        self.Strcai_zhiL=_detailes.material_name;
        if (lv_cai==YES) {
            self.Strcai_zhiL=_detailes.tradeMark;//牌号名称
        }
        //规格
        if (juan_cai==YES||ban__cai==YES||lv_cai) {
            NSArray*ary=[_detailes.spec_code componentsSeparatedByString:@"*"];
            self.StrthicknessT=ary[0];
            self.StrwidthT=ary[1];
            self.StrcT=ary[2];
        }
        //规格
        if (guan_cai==YES||xing_cai==YES) {
            _Strspecifications=_detailes.spec_code;
        }
        
        self.shengIDN=_detailes.supply_provinceID;//省ID
        self.cityIDN=_detailes.supply_cityID;//市ID
        
        self.StrsupplytoL=[NSString stringWithFormat:@"%@-%@",[ProvinceAndCity inputShengID:_detailes.supply_provinceID],[ProvinceAndCity inputCityID:_detailes.supply_cityID]];//供货地

        self.StrvalidityL=[NSString stringWithFormat:@"%@小时-%@分钟",_detailes.effective_hour,_detailes.effective_minute];//有效期
        self.StrsurfaceT=_detailes.supface_name;//表面
        self.StrtoleranceT=[NSString stringWithFormat:@"%@",_detailes.tolerance];//公差
        if (lv_cai==YES) {
            self.StrtoleranceT=[NSString stringWithFormat:@"%@",_detailes.nationalStandard];//国标
        }
        self.StrproducersL=_detailes.manufacturer_name;//生产商
        self.StrnumberCountT=[NSString stringWithFormat:@"%@",_detailes.quantity];//购买数量
        self.StrtotalCountT=[NSString stringWithFormat:@"%@",_detailes.weight];//总量
        //发票
        NSInteger isInvoice=[_detailes.is_nned_invoice integerValue];//将string转为integer类型
        NSString*is_nned_invoice=[NSString string];//是否需要发票
        if (isInvoice==0)
        {
            is_nned_invoice=@"不需要";
            self.invoiceN=@"0";
        }
        if (isInvoice==1)
        {
            is_nned_invoice=@"需要";
            self.invoiceN=@"1";
        }
        self.StrinvoiceL=is_nned_invoice;//是否需要发票
        
        self.Strnote=_detailes.remark;//备注
        
        if (_detailes.img_pathsAry.count>0) {
            //[_cImages addObjectsFromArray:_detailes.img_pathsAry];
           
            for (NSInteger i=0; i<_detailes.img_pathsAry.count;i++) {
                
                NSData*ImageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:_detailes.img_pathsAry[i]]];
                UIImage*image=[UIImage imageWithData:ImageData];
                [_cImages addObject:image];
            }
        }
    }

#pragma mark-------------订单详情页的重新采购
    if ([self.pageString isEqualToString:@"订单重新采购"]) {
        //类别
        self.StrclassTypeL=_orderDeta.categoryName;
    
        self.classTypeN=[NSString stringWithFormat:@"%@", _orderDeta.varietyID];//类别ID
        self.Strcai_zhiL=_orderDeta.materialName;//材质名称
        if (lv_cai==YES) {
            self.Strcai_zhiL=_orderDeta.tradeMark;//牌号名称
        }
        //规格
        if (juan_cai==YES||ban__cai==YES||lv_cai==YES) {
            NSArray*ary=[_orderDeta.specCode componentsSeparatedByString:@"*"];
            self.StrthicknessT=ary[0];
            self.StrwidthT=ary[1];
            self.StrcT=ary[2];
        }
        //规格
        if (guan_cai==YES||xing_cai==YES) {
            _Strspecifications=_orderDeta.specCode;
        }
        
        self.shengIDN=_orderDeta.supplyProvinceID;//省ID
        self.cityIDN=_orderDeta.supplyCityID;//市ID
        
        self.StrsupplytoL=[NSString stringWithFormat:@"%@-%@",[ProvinceAndCity inputShengID:_orderDeta.supplyProvinceID],[ProvinceAndCity inputCityID:_orderDeta.supplyCityID]];//供货地
        
        self.StrvalidityL=@"2小时-0分钟(默认)";//有效期
        self.StrsurfaceT=_orderDeta.surfaceName;//表面
        self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.tolerance];//公差
        if (lv_cai==YES) {
            self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.nationalStandard];//国标
        }
        self.StrproducersL=_orderDeta.manufacturerName;//生产商
        self.StrnumberCountT=[NSString stringWithFormat:@"%@",_orderDeta.quantity];//购买数量
        self.StrtotalCountT=[NSString stringWithFormat:@"%@",_orderDeta.weight];//总量
        //发票
        NSInteger isInvoice=[_orderDeta.isNeedInvoice integerValue];//将string转为integer类型
        NSString*is_nned_invoice=[NSString string];//是否需要发票
        if (isInvoice==0)
        {
            is_nned_invoice=@"不需要";
            self.invoiceN=@"0";
        }
        if (isInvoice==1)
        {
            is_nned_invoice=@"需要";
            self.invoiceN=@"1";
        }
        self.StrinvoiceL=is_nned_invoice;//是否需要发票
        
        self.Strnote=_orderDeta.purchaseRemark;//备注
        if (_orderDeta.imgPathesAry.count>0) {
            //[_cImages addObjectsFromArray:_detailes.img_pathsAry];
            for (NSInteger i=0; i<_orderDeta.imgPathesAry.count;i++) {
                
                NSData*ImageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:_orderDeta.imgPathesAry[i]]];
                UIImage*image=[UIImage imageWithData:ImageData];
                [_cImages addObject:image];
            }
        }

    }

    
    
#pragma mark-------------现货详情传过来的显示
    if ([self.pageString isEqualToString:@"试试吆喝找货"]) {
        //类别
        self.StrclassTypeL=_Datalist.CategoryName;
        
        if (dai_cai==YES) {
            self.StrclassTypeL=@"";
        }
        
       //品类id判断制作
        if (juan_cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"卷材"};
            [Controller requestWithURL:PostQueryVarietyName jsondic:dic finishBlock:^(ClassData *classData) {
                NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                self.StrnumberCountT=@"1";
                [_tableView reloadData];
            }];
        }
        
        
        if (ban__cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"板材"};
            [Controller requestWithURL:PostQueryVarietyName jsondic:dic finishBlock:^(ClassData *classData) {
                NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                [_tableView reloadData];
            }];
        }

        
        self.Strcai_zhiL=_Datalist.MaterialCode;//材质名称
        
//        if (lv_cai==YES) {
//            self.Strcai_zhiL=_orderDeta.tradeMark;//牌号名称
//        }
        
        //规格
        if (juan_cai==YES||ban__cai==YES||lv_cai==YES) {
            NSArray*ary=[_Datalist.SpecCode componentsSeparatedByString:@"*"];
            self.StrthicknessT=ary[0];
            self.StrwidthT=ary[1];
            self.StrcT=ary[2];
        }
        
        //规格
        if (guan_cai==YES||xing_cai==YES||dai_cai==YES) {
            _Strspecifications=_Datalist.SpecCode;
        }
        
        //默认定位城市  供货地
        if ([[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"]==nil) {
            
        }
        else{
            NSString*City=[[NSUserDefaults standardUserDefaults]objectForKey:@"NcityName"];
            NSString*Sheng=[[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"];
            self.StrsupplytoL=[NSString stringWithFormat:@"%@-%@",Sheng,City];
            self.shengIDN=[ProvinceAndCity inputShengName:Sheng];
            self.cityIDN=[ProvinceAndCity inputCityName:City];
        }
        self.StrvalidityL=@"2小时-0分钟(默认)";//有效期
        self.StrsurfaceT=_Datalist.SurfaceCode;//表面
        
//        self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.tolerance];//公差
//        if (lv_cai==YES) {
//            self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.nationalStandard];//国标
//        }
        
        
        
        self.StrproducersL=_Datalist.FactoryName;//生产商
        self.StrnumberCountT=[NSString stringWithFormat:@"%@",_Datalist.Quantity];//购买数量
//        self.StrtotalCountT=[NSString stringWithFormat:@"%@",_Datalist.TotalWeight];//总量
        
        //发票
//        NSInteger isInvoice=[_orderDeta.isNeedInvoice integerValue];//将string转为integer类型
//        NSString*is_nned_invoice=[NSString string];//是否需要发票
//        if (isInvoice==0)
//        {
//            is_nned_invoice=@"不需要";
//            self.invoiceN=@"0";
//        }
//        if (isInvoice==1)
//        {
//            is_nned_invoice=@"需要";
//            self.invoiceN=@"1";
//        }
//        self.StrinvoiceL=is_nned_invoice;//是否需要发票
        
        _invoiceN=@"1";
        _switchN=@"0";
        self.Strnote=_Datalist.Remark;//备注
        
//        if (_orderDeta.imgPathesAry.count>0) {
//            //[_cImages addObjectsFromArray:_detailes.img_pathsAry];
//            for (NSInteger i=0; i<_orderDeta.imgPathesAry.count;i++) {
//                
//                NSData*ImageData=[NSData dataWithContentsOfURL:[NSURL URLWithString:_orderDeta.imgPathesAry[i]]];
//                UIImage*image=[UIImage imageWithData:ImageData];
//                [_cImages addObject:image];
//            }
//        }
        
    }

    
    
    
    
#pragma mark--------------直接发布求购的数据设置
    if ([self.pageString isEqualToString:@"直接采购"]) {
        if ([[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"]==nil) {
            
        }
        else{
            NSString*City=[[NSUserDefaults standardUserDefaults]objectForKey:@"NcityName"];
            NSString*Sheng=[[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"];
            self.StrsupplytoL=[NSString stringWithFormat:@"%@-%@",Sheng,City];
            self.shengIDN=[ProvinceAndCity inputShengName:Sheng];
            self.cityIDN=[ProvinceAndCity inputCityName:City];
        }

        if (juan_cai==YES)
        {
            self.StrcT=@"C";
        }
        self.StrvalidityL=@"2小时-0分钟(默认)";
        self.StrproducersL=@"不限";
        if (juan_cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"卷材"};
            [Controller requestWithURL:@"AppPurchaseInfo/PostQueryVarietyName?from=app" jsondic:dic finishBlock:^(ClassData *classData) {
               NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                self.StrnumberCountT=@"1";
                [_tableView reloadData];
           }];
        }
        if (ban__cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"板材"};
            [Controller requestWithURL:@"AppPurchaseInfo/PostQueryVarietyName?from=app" jsondic:dic finishBlock:^(ClassData *classData) {
                NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                [_tableView reloadData];
            }];
        }
        _invoiceN=@"1";
        _switchN=@"0";
    }

    
    
    
#pragma mark--------------我要买
    
    if ([self.pageString isEqualToString:@"我要买"]) {
        //类别
        self.StrclassTypeL=_searchListItemModel.ProductSortName;
        
        //品类id判断制作
        if (juan_cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"卷材"};
            [Controller requestWithURL:PostQueryVarietyName jsondic:dic finishBlock:^(ClassData *classData) {
                NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                self.StrnumberCountT=@"1";
                [_tableView reloadData];
            }];
        }
        if (ban__cai==YES)
        {
            NSDictionary*dic=@{@"CATEGORY_NAME":@"板材"};
            [Controller requestWithURL:PostQueryVarietyName jsondic:dic finishBlock:^(ClassData *classData) {
                NSArray*ary=classData.data;
                _classTypeN=ary[0][@"value"];
                [_tableView reloadData];
            }];
        }
        
        self.Strcai_zhiL=_searchListItemModel.MaterialName;//材质名称
        
        //        if (lv_cai==YES) {
        //            self.Strcai_zhiL=_orderDeta.tradeMark;//牌号名称
        //        }
        
        //规格
        if (juan_cai==YES||ban__cai==YES||lv_cai==YES) {
//            NSArray*ary=[_Datalist.SpecCode componentsSeparatedByString:@"*"];
            self.StrthicknessT=_searchListItemModel.ThickName;
            self.StrwidthT=_searchListItemModel.WidthName;
            if (juan_cai==YES) {
                self.StrcT=@"C";
            }else{
                self.StrcT=@"";
            }
            
        }
        
        //规格
        if (guan_cai==YES||xing_cai==YES) {
            NSString *st=[NSString stringWithFormat:@"%@*%@",_searchListItemModel.ThickName,_searchListItemModel.WidthName];
            _Strspecifications=st;
        }
        
        //默认定位城市  供货地
        if ([[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"]==nil) {
            
        }
        else{
            NSString*City=[[NSUserDefaults standardUserDefaults]objectForKey:@"NcityName"];
            NSString*Sheng=[[NSUserDefaults standardUserDefaults]objectForKey:@"NshengName"];
            self.StrsupplytoL=[NSString stringWithFormat:@"%@-%@",Sheng,City];
            self.shengIDN=[ProvinceAndCity inputShengName:Sheng];
            self.cityIDN=[ProvinceAndCity inputCityName:City];
        }
        self.StrvalidityL=@"2小时-0分钟(默认)";//有效期
        self.StrsurfaceT=_searchListItemModel.SurfaceName;//表面
        
        //        self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.tolerance];//公差
        //        if (lv_cai==YES) {
        //            self.StrtoleranceT=[NSString stringWithFormat:@"%@",_orderDeta.nationalStandard];//国标
        //        }
        
        
        self.StrproducersL=_searchListItemModel.FactoryName;//生产商
        
        _invoiceN=@"1";
        _switchN=@"0";
        self.Strnote=_searchListItemModel.Remark;//备注
        
    }
    
    //初始化表格
    _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, width, height-kNavigationBarHeight-kTabBarHeight) style:UITableViewStylePlain];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    [self.view addSubview:_tableView];
    
    UIView*backView=[[UIView alloc]init];
    backView.backgroundColor=[UIColor groupTableViewBackgroundColor];
    [self.view addSubview:backView];
    [backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);     make.right.offset(0);
        make.bottom.offset(0);   make.height.offset(60);
    }];
    
    //电话找货按钮
    UIButton*phoneBtnz=[UIButton buttonWithType:UIButtonTypeCustom];
    phoneBtnz.layer.masksToBounds=YES;
    phoneBtnz.layer.cornerRadius=18;
    [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"Phone_call_for_goods"] forState:UIControlStateNormal];
    [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"phoneFindHF"] forState:UIControlStateHighlighted];
    [phoneBtnz addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];
    [backView addSubview:phoneBtnz];
    [phoneBtnz mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(20);
        make.height.offset(36);
        make.width.offset(36);
        make.bottom.offset(-12);
    }];
    //立即发布按钮
    _issueBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    _issueBtn.layer.masksToBounds=YES;
    _issueBtn.layer.cornerRadius=20;
    [_issueBtn setBackgroundImage:[UIImage imageNamed:@"orangeButton_13"] forState:UIControlStateNormal];
    [_issueBtn setBackgroundImage:[UIImage imageNamed:@"orangeButton_13_hl"] forState:UIControlStateHighlighted];
    [_issueBtn addTarget:self action:@selector(issueBtn) forControlEvents:UIControlEventTouchUpInside];
    [_issueBtn setTitle:@"立即发布求购" forState:UIControlStateNormal];
    [_issueBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backView addSubview:_issueBtn];
    [_issueBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(phoneBtnz.mas_right).offset(10);
        make.right.offset(-20);
        make.height.offset(36);
        make.bottom.offset(-12);
    }];

}

#pragma mark--------------表格的协议方法
//返回多少分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}
//每个分区有多少行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    //第一分区分别返回不同的行数
    if (section==0)
    {
        if (juan_cai==YES||ban__cai==YES)
        {
            return 4;
        }
        if (guan_cai||xing_cai||lv_cai||dai_cai==YES)
        {
            return 5;
        }
    }
    if (section==1)
    {
        return 5;
    }
    return 4;
}
//区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
//每一行单元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==2)
    {
        if (indexPath.row==2)
        {
            return 80;
        }
        if (indexPath.row==3)
        {
            return (width-80)/3*2+50;
        }
        return 60;
    }
    return 60;
}
#pragma mark--------------单元格要显示的东西
//表格上要展示的东西
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//***************** 第0个分区
    if (indexPath.section==0)
    {
        cell1=[[UITableViewCell alloc]init];
        cell1.selectionStyle=UITableViewCellSelectionStyleNone;
        cell1.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell1.textLabel.font=font15;
        //必填的星星图标
        UIImageView*startImage=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bi_tian"]];
        startImage.frame=CGRectMake(2,cell1.frame.size.height/2, 10, 10);
        [cell1 addSubview:startImage];
        //钢卷、板卷前方显示的内容
        NSArray*Array1=[NSArray arrayWithObjects:@"材质:",@"规格:",@"供货地:",@"有效期:" ,nil];
        NSArray*Array2=[NSArray arrayWithObjects:@"类别:",@"材质:",@"规格:",@"供货地:",@"有效期:", nil];
        NSArray*Array3=[NSArray arrayWithObjects:@"类别:",@"牌号",@"规格:",@"供货地:",@"有效期:", nil];
        //******如果点击的是钢卷或板卷
        if (juan_cai==YES||ban__cai==YES)
        {
            cell1.textLabel.font=font15;
            cell1.textLabel.text=Array1[indexPath.row];
            if (indexPath.row==1)
            {
                cell1.accessoryType=UITableViewCellAccessoryNone;
            }
            if (indexPath.row==0)
            {
                //材质
                cai_zhiL=[[UILabel alloc]init];
                cai_zhiL.font=font14;
                cai_zhiL.textColor=gayColor;
                cai_zhiL.frame=CGRectMake(100, 0, width-130, 60);
                cai_zhiL.text=_Strcai_zhiL;
                //cai_zhiL.text=@"材质";
                cai_zhiL.textAlignment=NSTextAlignmentRight;
                [cell1 addSubview:cai_zhiL];
            }
            if (indexPath.row==1)
            {
                NSInteger  threeW=(width-100)/3;
                //厚度输入框
                _thicknessT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, threeW-2, 60)];
                _thicknessT.placeholder=@"厚度";
                _thicknessT.textAlignment=NSTextAlignmentCenter;
                _thicknessT.font=font14;
                _thicknessT.textColor=gayColor;
                _thicknessT.text=_StrthicknessT;
                _thicknessT.delegate=self;
                [_thicknessT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                [cell1 addSubview:_thicknessT];
                
                UIImageView*lineImg1=[[UIImageView alloc]init];
                lineImg1.frame=CGRectMake(100+threeW-1, 8, 0.5, 44);
                lineImg1.backgroundColor=[UIColor lightGrayColor];
                [cell1 addSubview:lineImg1];
                
                //宽度
                _widthT=[[UITextField alloc]initWithFrame:CGRectMake(100+threeW, 0, threeW-2, 60)];
                _widthT.placeholder=@"宽度";
                _widthT.textAlignment=NSTextAlignmentCenter;
                _widthT.font=font14;
                _widthT.textColor=gayColor;
                _widthT.text=_StrwidthT;
                _widthT.delegate=self;
                [_widthT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                [cell1 addSubview:_widthT];
                
                UIImageView*lineImg2=[[UIImageView alloc]init];
                lineImg2.frame=CGRectMake(100+threeW*2-1, 8, 0.5, 44);
                lineImg2.backgroundColor=[UIColor lightGrayColor];
                [cell1 addSubview:lineImg2];

                
                //长度，或C
                _cT=[[UITextField alloc]initWithFrame:CGRectMake(100+threeW*2, 0, threeW-20, 60)];
                _cT.font=font14;
                if (juan_cai==YES)
                {
                    _cT.text=@"C";
                    UIButton*ctBtn=[[UIButton alloc]init];
                    ctBtn.frame=CGRectMake(0, 0, threeW-20, 60);
                    //ctBtn.backgroundColor=[UIColor yellowColor];
                    [_cT  addSubview:ctBtn];

                }
                _cT.placeholder=@"长度";
                _cT.textAlignment=NSTextAlignmentCenter;
                _cT.font=font14;
                _cT.textColor=gayColor;
                _cT.text=_StrcT;
                _cT.delegate=self;
                [_cT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                [cell1 addSubview:_cT];
            }
            if (indexPath.row==2)
            {
                //供货地
                _supplytoL=[[UILabel alloc]init];
                _supplytoL.frame=CGRectMake(100, 0, width-130, 60);
                _supplytoL.textAlignment=NSTextAlignmentRight;
                _supplytoL.font=font14;
                _supplytoL.textColor=gayColor;
                _supplytoL.text=_StrsupplytoL;
                [cell1 addSubview:_supplytoL];
            }
            if (indexPath.row==3)
            {
                //有效期
                _validityL=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
                _validityL.textAlignment=NSTextAlignmentRight;
                _validityL.text=@"2小时0分钟(默认)";
                _validityL.font=font14;
                _validityL.textColor=gayColor;
                _validityL.text=_StrvalidityL;
                [cell1 addSubview:_validityL];
            }
        }
        //******如果点击的是管材或型材
        if (guan_cai==YES||xing_cai==YES||lv_cai==YES||dai_cai==YES)
        {
            if (guan_cai==YES||xing_cai==YES||dai_cai==YES) {
                cell1.textLabel.text=Array2[indexPath.row];
            }
            if (lv_cai==YES) {
                cell1.textLabel.text=Array3[indexPath.row];
            }

            if (indexPath.row==0)
            {
                //类别
                _classTypeL=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
                _classTypeL.font=font14;
                _classTypeL.textColor=gayColor;
                _classTypeL.text=_StrclassTypeL;
                _classTypeL.textAlignment=NSTextAlignmentRight;
                [cell1 addSubview:_classTypeL];
                
                
            }
            if (indexPath.row==1)
            {
                if (lv_cai==YES) {
                     cell1.accessoryType=UITableViewCellAccessoryNone;
                    _paiHao=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
                    _paiHao.textColor=gayColor;
                    _paiHao.placeholder=@"牌号";
                    _paiHao.text=_Strcai_zhiL;
                    _paiHao.font=font14;
                    _paiHao.delegate=self;
                    _paiHao.textAlignment=NSTextAlignmentRight;
                    [_paiHao addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                    [cell1 addSubview:_paiHao];

                }
                else{
                    //材质
                    cai_zhiL=[[UILabel alloc]init];
                    cai_zhiL.textColor=[UIColor grayColor];
                    cai_zhiL.frame=CGRectMake(100, 0, width-130, 60);
                    //cai_zhiL.text=@"材质";
                    cai_zhiL.textColor=gayColor;
                    cai_zhiL.text=_Strcai_zhiL;
                    cai_zhiL.textAlignment=NSTextAlignmentRight;
                    cai_zhiL.font=font14;
                    [cell1 addSubview:cai_zhiL];
                }
            }
            if (indexPath.row==2)
            {
                cell1.accessoryType=UITableViewCellAccessoryNone;
                if (lv_cai==YES) {
                    NSInteger  threeW=(width-100)/3;
                    //厚度输入框
                    _thicknessT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, threeW-2, 60)];
                    _thicknessT.placeholder=@"厚度";
                    _thicknessT.textAlignment=NSTextAlignmentCenter;
                    _thicknessT.font=font14;
                    _thicknessT.textColor=gayColor;
                    _thicknessT.text=_StrthicknessT;
                    _thicknessT.delegate=self;
                    [_thicknessT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                    [cell1 addSubview:_thicknessT];
                    
                    UIImageView*lineImg1=[[UIImageView alloc]init];
                    lineImg1.frame=CGRectMake(100+threeW-1, 8, 0.5, 44);
                    lineImg1.backgroundColor=[UIColor lightGrayColor];
                    [cell1 addSubview:lineImg1];
                    
                    //宽度
                    _widthT=[[UITextField alloc]initWithFrame:CGRectMake(100+threeW, 0, threeW-2, 60)];
                    _widthT.placeholder=@"宽度";
                    _widthT.textAlignment=NSTextAlignmentCenter;
                    _widthT.font=font14;
                    _widthT.textColor=gayColor;
                    _widthT.text=_StrwidthT;
                    _widthT.delegate=self;
                    [_widthT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                    [cell1 addSubview:_widthT];
                    
                    UIImageView*lineImg2=[[UIImageView alloc]init];
                    lineImg2.frame=CGRectMake(100+threeW*2-1, 8, 0.5, 44);
                    lineImg2.backgroundColor=[UIColor lightGrayColor];
                    [cell1 addSubview:lineImg2];
                    
                    
                    //长度，或C
                    _cT=[[UITextField alloc]initWithFrame:CGRectMake(100+threeW*2, 0, threeW-20, 60)];
                    _cT.font=font14;
                    _cT.placeholder=@"长度";
                    _cT.textAlignment=NSTextAlignmentCenter;
                    _cT.font=font14;
                    _cT.textColor=gayColor;
                    _cT.text=_StrcT;
                    _cT.delegate=self;
                    [_cT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                    [cell1 addSubview:_cT];
                }
                else{
                    //规格
                    _specifications=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
                    _specifications.textColor=gayColor;
                    _specifications.placeholder=@"规格";
                    _specifications.text=_Strspecifications;
                    _specifications.font=font14;
                    _specifications.delegate=self;
                    _specifications.textAlignment=NSTextAlignmentRight;
                    [_specifications addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
                    [cell1 addSubview:_specifications];
                }
            }
            if (indexPath.row==3)
            {
                //供货地
                _supplytoL=[[UILabel alloc]init];
                _supplytoL.frame=CGRectMake(100, 0, width-130, 60);
                _supplytoL.textAlignment=NSTextAlignmentRight;
                _supplytoL.font=font14;
                _supplytoL.textColor=gayColor;
                _supplytoL.text=_StrsupplytoL;
                [cell1 addSubview:_supplytoL];
            }
            if (indexPath.row==4)
            {
                //有效期
                _validityL=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
                _validityL.textAlignment=NSTextAlignmentRight;
                //_validityL.text=@"2小时0分钟(默认)";
                _validityL.font=font14;
                _validityL.textColor=gayColor;
                _validityL.text=_StrvalidityL;
                [cell1 addSubview:_validityL];
            }
        }
        return cell1;
    }
//***************** 第1个分区
    if (indexPath.section==1)
    {
        UITableViewCell*cell2=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        NSArray*cell2_array=@[@"表面:",@"公差:",@"生产商:",@"总量:",@"数量:"];
        cell2.selectionStyle=UITableViewCellSelectionStyleNone;
        cell2.textLabel.font=font15;
        if (lv_cai==YES) {
            if (indexPath.row==1) {
                cell2.textLabel.text=@"国标";
                cell2.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            }
            else{
               cell2.textLabel.text=cell2_array[indexPath.row];
            }
        }
        else{
            cell2.textLabel.text=cell2_array[indexPath.row];
        }
    
        if (indexPath.row==0)
        {
            cell2.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            //表面
            _surfaceT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
            _surfaceT.userInteractionEnabled=NO;
            _surfaceT.textAlignment=NSTextAlignmentRight;
            _surfaceT.placeholder=@"表面";
            _surfaceT.font=font14;
            _surfaceT.textColor=gayColor;
            _surfaceT.text=_StrsurfaceT;
            _surfaceT.delegate=self;
            _surfaceT.tag=190;
            [_surfaceT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
            [cell2 addSubview:_surfaceT];
        }
        if (indexPath.row==1)
        {
            //公差
            _toleranceT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
            _toleranceT.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
            if (lv_cai==YES) {
                _toleranceT.userInteractionEnabled=NO;
            }
            else{
                _toleranceT.placeholder=@"允许格式如1.15或者1.25-1.31";
            }
            _toleranceT.textAlignment=NSTextAlignmentRight;
            _toleranceT.font=font14;
            _toleranceT.textColor=gayColor;
            _toleranceT.text=_StrtoleranceT;
            _toleranceT.delegate=self;
            _toleranceT.tag=191;
            [_toleranceT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
            [cell2 addSubview:_toleranceT];
        }
        if (indexPath.row==2)
        {
            //生产商
            cell2.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
            _producersL=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
            _producersL.text=@"不限";
            _producersL.textColor=gayColor;
            _producersL.font=font14;
            _producersL.text=_StrproducersL;
            _producersL.textAlignment=NSTextAlignmentRight;
            [cell2 addSubview:_producersL];
        }
        if (indexPath.row==3)
        {
            //总量
            _totalCountT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
            _totalCountT.placeholder=@"单位为吨";
            _totalCountT.textColor=gayColor;
            _totalCountT.font=font14;
            _totalCountT.text=_StrtotalCountT;
            _totalCountT.textAlignment=NSTextAlignmentRight;
            _totalCountT.delegate=self;
            _totalCountT.tag=193;
            [_totalCountT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
            [cell2 addSubview:_totalCountT];
        }
        if (indexPath.row==4)
        {
            //数量
            _numberCountT=[[UITextField alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
            _numberCountT.font=font14;
            _numberCountT.textColor=gayColor;
            if (juan_cai==YES||dai_cai==YES){
                _numberCountT.text=@"1";
            }
            if (ban__cai==YES){
                _numberCountT.placeholder=@"张";
            }
            if (guan_cai==YES){
                _numberCountT.placeholder=@"支";
            }
            if (xing_cai==YES){
                _numberCountT.placeholder=@"个";
            }
            _numberCountT.text=_StrnumberCountT;
            _numberCountT.textAlignment=NSTextAlignmentRight;
            _numberCountT.delegate=self;
            _numberCountT.tag=194;
            [_numberCountT addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
            [cell2 addSubview:_numberCountT];
        }
        return cell2;
    }
//***************** 第2个分区
    UITableViewCell*cell3=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    NSArray*cell3_array=@[@"发票:",@"备注:",@"免扰模式:",@""];
    cell3.selectionStyle=UITableViewCellSelectionStyleNone;
    cell3.textLabel.font=font15;
    if (indexPath.row==0)
    {
        cell3.textLabel.text=cell3_array[0];
        cell3.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        _invoiceL=[[UILabel alloc]initWithFrame:CGRectMake(100, 0, width-130, 60)];
        _invoiceL.text=@"需要";
        _invoiceL.textColor=gayColor;
        _invoiceL.textAlignment=NSTextAlignmentRight;
        _invoiceL.font=font14;
        _invoiceL.text=_StrinvoiceL;
        [cell3 addSubview:_invoiceL];
    }
    if (indexPath.row==1)
    {
        cell3.textLabel.text=cell3_array[1];
        _note=[[UITextField alloc]initWithFrame:CGRectMake(60, 0, width-70, 60)];
        _note.placeholder=@"如有其他要求请在此处填写";
        _note.textColor=gayColor;
        _note.text=_Strnote;
        _note.font=font14;
        _note.delegate=self;
        _note.tag=291;
        [_note addTarget:self action:@selector(disMiss) forControlEvents:UIControlEventEditingDidEndOnExit];
        [cell3 addSubview:_note];
    }
    if (indexPath.row==2)
    {
        UILabel*label1=[[UILabel alloc]init];
        label1.text=@"免扰模式:";
        label1.frame=CGRectMake(15, 10, 100, 30);
        label1.font=font15;
        [cell3 addSubview:label1];
        UILabel*label2=[[UILabel alloc]init];
        label2.text=@"锁卖家货后,不展示联系信息给卖家,以防被骚扰";
        label2.frame=CGRectMake(15, 40, 280, 30);
        label2.font=[UIFont systemFontOfSize:12];
        label2.textColor=[UIColor grayColor];
        [cell3 addSubview:label2];
        
        //开关
        _off=[[UISwitch alloc]init];
        _off.frame=CGRectMake(width-60, 25, 51, 31);
        _off.on=_ISOFF;
        [_off addTarget:self action:@selector(changeOFF) forControlEvents:UIControlEventTouchUpInside];
        [cell3 addSubview:_off];
    }
    if (indexPath.row==3)
    {
        
        //表格布局加载图片
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
        //设置单元格的大小
        layout.itemSize = CGSizeMake((width-32)/3,(width-32)/3);
        layout.minimumInteritemSpacing = 10;
        layout.minimumLineSpacing = 10;
        layout.scrollDirection = UICollectionViewScrollDirectionVertical;
        //设置上下左右四个方向item距离边界的长度
        layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        _collectionView = [[UICollectionView alloc]initWithFrame:[[UIScreen mainScreen] bounds] collectionViewLayout:layout];
        //_collectionView默认背景颜色是黑色
        _collectionView.backgroundColor = [UIColor whiteColor];
        //设置数据源和代理
        _collectionView.dataSource  = self;
        _collectionView.delegate = self;
        [_collectionView registerNib:[UINib nibWithNibName:@"MyCell" bundle:nil] forCellWithReuseIdentifier:@"cell"];
        _collectionView.frame=CGRectMake(0, 0, width, (width-80)/3*2+50);
        [cell3 addSubview:_collectionView];

        
    }
    return cell3;
}

#pragma mark--------------------选中单元格时执行的方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:indexPath.row  inSection:indexPath.section];
    [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
    [self.view endEditing:YES];

    if (indexPath.section==0)
   {
    //如果是从板材或卷材页面进来的
        if (juan_cai==YES||ban__cai==YES)
        {
            if (indexPath.row==0)
            {
                //弹出材质的选择器
                [TypePicker showPickerView:self.view withTitle:@"材质选择" andSelectBlock:^(NSString *dataString) {
                    self.Strcai_zhiL=dataString;
                    [_tableView reloadData];
                }];
            }
            if (indexPath.row==2)
            {
                //弹出供货地选择器
                [CityPicker showPickerView:self.view withTitle:@"城市选择" andSelectBlock:^(NSString *str) {
                    NSArray*array=[str componentsSeparatedByString:@"*"];
                    self.StrsupplytoL=array[0];
                    NSString*IDString=array[1];
                    //省市ID
                    NSArray*IDarray=[IDString componentsSeparatedByString:@"|"];
                    self.shengIDN=IDarray[0];
                    self.cityIDN=IDarray[1];
                    [_tableView reloadData];
                }];
            }
            if (indexPath.row==3)
            {
                //弹出有效期时间的选择器
                [SinglePicker showPickerView:self.view withdataArray:nil withTitle:@"有效期选择"  singleDoble:(BOOL)NO andSelectBlock:^(NSString *dateString)  {
                    self.StrvalidityL=dateString;
                    [_tableView reloadData];
                }];
            }
        }
        //如果是从管材或型材页面进来的
        if (guan_cai==YES||xing_cai==YES||lv_cai==YES||dai_cai==YES)
        {
            if (indexPath.section==0)
            {
                if (indexPath.row==0)
                {
                    //弹出类别的选择器
                    if (guan_cai==YES) {
                        [TypeClassPicker showPickerView:self.view withTitle:@"类别选择" typStr:@"管材" andSelectBlock:^(NSString *str) {
                            NSArray*aty=[str componentsSeparatedByString:@"|"];
                            self.StrclassTypeL=aty[0];
                            self.classTypeN=aty[1];
                            [_tableView reloadData];
                        }];
                      }
                    
                    //弹出类别的选择器
                    if (dai_cai==YES) {
                        [TypeClassPicker showPickerView:self.view withTitle:@"类别选择" typStr:@"带材" andSelectBlock:^(NSString *str) {
                            NSArray*aty=[str componentsSeparatedByString:@"|"];
                            self.StrclassTypeL=aty[0];
                            self.classTypeN=aty[1];
                            [_tableView reloadData];
                        }];
                    }

                    
                    if (xing_cai==YES) {
                            [TypeClassPicker showPickerView:self.view withTitle:@"类别选择" typStr:@"型材" andSelectBlock:^(NSString *str) {
                                NSArray*aty=[str componentsSeparatedByString:@"|"];
                                self.StrclassTypeL=aty[0];
                                self.classTypeN=aty[1];
                                [_tableView reloadData];
                            }];

                        }
                    if (lv_cai==YES) {
                        [TypeClassPicker showPickerView:self.view withTitle:@"类别选择" typStr:@"铝材" andSelectBlock:^(NSString *str) {
                            NSArray*aty=[str componentsSeparatedByString:@"|"];
                            self.StrclassTypeL=aty[0];
                            self.classTypeN=aty[1];
                            [_tableView reloadData];
                        }];
                    }
                
                }
                if (indexPath.row==1)
                {
                    if (lv_cai==NO) {
                        //弹出材质的选择器
                        [TypePicker showPickerView:self.view withTitle:@"材质选择" andSelectBlock:^(NSString *dataString) {
                            self.Strcai_zhiL=dataString;
                            [_tableView reloadData];
                        }];
                     }
                }
                if (indexPath.row==3)
                {
                    //弹出供货地选择器
                    [CityPicker showPickerView:self.view withTitle:@"城市选择" andSelectBlock:^(NSString *str) {
                        NSArray*array=[str componentsSeparatedByString:@"*"];
                        self.StrsupplytoL=array[0];
                        NSString*IDString=array[1];
                        //省市ID
                        NSArray*IDarray=[IDString componentsSeparatedByString:@"|"];
                        self.shengIDN=IDarray[0];
                        self.cityIDN=IDarray[1];
                        [_tableView reloadData];
                    }];

                }
                if (indexPath.row==4)
                {
                    //弹出有效期时间的选择器
                    
                    [SinglePicker showPickerView:self.view withdataArray:nil withTitle:@"有效期选择"  singleDoble:(BOOL)NO andSelectBlock:^(NSString *dateString)  {
                        self.StrvalidityL=dateString;
                        //分割时间，有利于参数请求
                        NSArray*array=[self.StrvalidityL componentsSeparatedByString:@"-"];
                        NSString*strH=[array[0] stringByReplacingOccurrencesOfString:@"小时" withString:@""];
                        self.hoursN=strH;
                        NSString*strM=[array[1] stringByReplacingOccurrencesOfString:@"分钟" withString:@""];
                        self.minutesN=strM;
                        [_tableView reloadData];
                    }];

                }
            }
        }
       }
    if (indexPath.section==1)
    {
        if (indexPath.row==0) {
            [SurfacePicker showPickerView:self.view withdataUrl:@"AppPurchaseInfo/PostSurfaceInfo?from=app" withTitle:@"表面选择" andSelectBlock:^(NSString *Sstr) {
                NSArray*ary=[Sstr componentsSeparatedByString:@"|"];
                _StrsurfaceT=ary[0];
                [_tableView reloadData];
            }];
        }
        if (lv_cai==YES) {
            if (indexPath.row==1) {
                NSArray*ary=[[NSArray alloc]initWithObjects:@"老国标",@"新国标",nil];
                [SinglePicker showPickerView:self.view withdataArray:ary withTitle:@"国标选择" singleDoble:YES andSelectBlock:^(NSString *Sstr) {
                    _StrtoleranceT=Sstr;
                    [_tableView reloadData];
                }];
            }
        }
        if (indexPath.row==2)
        {
            //弹出生产商的选择器
            [ProducersPicker showPickerView:self.view withTitle:@"选择生产商" selectString:_StrproducersL  andSelectBlock:^(NSString *dateString) {
                self.StrproducersL=dateString;
                [_tableView reloadData];
            }];
        }
    }
    if (indexPath.section==2)
    {
        if (indexPath.row==0)
        {
            //弹出是否需要发票
            NSArray*array=[[NSArray alloc]initWithObjects:@"需要",@"不需要",nil];
            [SinglePicker showPickerView:self.view withdataArray:array withTitle:@"是否需要发票" singleDoble:YES andSelectBlock:^(NSString *dataString) {
                self.StrinvoiceL=dataString;
                if ([self.StrinvoiceL isEqualToString:@"需要"])
                {
                    self.invoiceN=@"1";
                }
                if ([self.StrinvoiceL isEqualToString:@"不需要"]) {
                    self.invoiceN=@"0";
                }
                [_tableView reloadData];
            }];
        }
    }
    
}

#pragma mark-------------UICollectionView的协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (_cImages==nil) {
        return 1;
    }
    return  _cImages.count+1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    
    //cell.backgroundColor = [UIColor colorWithRed:arc4random()%256/255.0 green:arc4random()%256/255.0 blue:arc4random()%256/255.0 alpha:1];
    
    if (indexPath.row==_cImages.count) {
        //cell.Img.hidden=YES;
        cell.clickRemove.hidden=YES;
        cell.addImage.hidden=NO;
        cell.Img.layer.borderWidth=0.3;
        cell.Img.layer.borderColor=[UIColor lightGrayColor].CGColor;
        cell.Img.image=nil;
    }
    else{
        cell.Img.hidden=NO;
        cell.clickRemove.hidden=NO;
        cell.addImage.hidden=YES;
    
//       if ([_cImages[indexPath.row] hasPrefix:@"http"]) {
//           [cell.Img sd_setImageWithURL:[NSURL URLWithString:_cImages[indexPath.row]]];
//        }
//       else {
           cell.Img.image=_cImages[indexPath.row];
//       }
        [cell.clickRemove addTarget:self action:@selector(remove:) forControlEvents:UIControlEventTouchUpInside];
        cell.clickRemove.tag=indexPath.row;
    }
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==_cImages.count) {
        if(_cImages.count==5)
        {
            ALERTSHOW(@"最多只能上传5张图片");
            return;
        }
        UIActionSheet *sheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"拍照" otherButtonTitles:@"从相册选择", nil];
        [sheet showInView:self.view];
    }
}

//移除图片的方法
-(void)remove:(UIButton*)btn
{
    [_cImages removeObjectAtIndex:btn.tag];
    [_collectionView reloadData];
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    //拍照
    if (buttonIndex== 0) {
        
        BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
        if(!isCamera)
        {
            ALERTSHOW(@"无法调用相机,请检查系统设置");
            return;
        }
        _imagePickerController = [[UIImagePickerController alloc] init];
        _imagePickerController.sourceType= UIImagePickerControllerSourceTypeCamera;
        _imagePickerController.delegate=self;
        //编辑模式
        _imagePickerController.allowsEditing= YES;
        [self presentViewController:_imagePickerController animated:YES completion:nil];
        
    }
    else if (buttonIndex == 1) {
        //从相册选择
        _imagePickerController= [[UIImagePickerController alloc] init];
        //设置picker类型
        _imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //设置代理
        _imagePickerController.delegate = self;
        //设置图片可以修改
        _imagePickerController.allowsEditing = YES;
        [self presentViewController:_imagePickerController animated:YES completion:nil];
    }
}

#pragma mark - UIIMAGE PICKER DELEGATE
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
        if ([type isEqualToString:@"public.image"]) {
            UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
            
            UIImageWriteToSavedPhotosAlbum(image, self,
                                           @selector(image:didFinishSavingWithError:contextInfo:),
                                           nil);
        }
    }
    else{
        
        [_imagePickerController dismissViewControllerAnimated:YES completion:^{
            UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
            [_cImages addObject: image];
            [_collectionView reloadData];
        }];
    }
}

//点击相册页面的取消按钮返回
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [_imagePickerController dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -------------------- 照片保存后
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo{
    if (!error) {
        [_imagePickerController dismissViewControllerAnimated:YES completion:^{
            [_cImages addObject: image];
            [_collectionView reloadData];
        }];
    }
}

#pragma mark------------------其他点击按钮，输入框的协议方法
//点击按钮，发布求购
-(void)issueBtn
{
    
    [MobClick event:@"immediatelyReleasePurchasing"];
    
    //分割时间，有利于参数请求
    NSArray*array=[self.StrvalidityL componentsSeparatedByString:@"-"];
    NSString*strH=[array[0] stringByReplacingOccurrencesOfString:@"小时" withString:@""];
    self.hoursN=strH;
    NSString*strM=[array[1] stringByReplacingOccurrencesOfString:@"分钟" withString:@""];
    self.minutesN=strM;
    if (_ISOFF==YES){
        _switchN=@"1";
    }
    if (_ISOFF==NO){
        _switchN=@"0";
    }
    if (_classTypeN==nil){
        ALERTSHOW(@"类别不能为空");
        return;
    }
    if (_Strcai_zhiL.length==0){
        if(lv_cai==YES){
            ALERTSHOW(@"牌号不能为空");
        }
        else{
           ALERTSHOW(@"材质不能为空");
        }return;
    }
    if ([_Strcai_zhiL isEqualToString:@"材质"]) {
        ALERTSHOW(@"请选择材质类型");
        return;
    }
    if (juan_cai==YES||ban__cai==YES||lv_cai==YES){
        if (_StrthicknessT.length==0){
            ALERTSHOW(@"厚度不能为空");
            return;
        }
        if (_StrwidthT.length==0){
            ALERTSHOW(@"宽度不能为空");
            return;
        }
        if (juan_cai==YES||dai_cai==YES) {
            _Strspecifications=[NSString stringWithFormat:@"%@*%@*C",_StrthicknessT,_StrwidthT];
        }
        if (ban__cai==YES||lv_cai==YES) {
            _Strspecifications=[NSString stringWithFormat:@"%@*%@*%@",_StrthicknessT,_StrwidthT,_StrcT];
        }
    }
    if (guan_cai==YES||xing_cai==YES||dai_cai==YES) {
        if(_Strspecifications.length==0)
        {
            ALERTSHOW(@"请输入规格");
            return;
        }
    }
    if (_shengIDN==nil||_cityIDN==nil){
        ALERTSHOW(@"供货地不能为空");
        return;
    }
    
    if ([_StrvalidityL isEqualToString:@"2小时-0分钟(默认)"]){
        _hoursN=@"2";
        _minutesN=@"0";
    }
    if ([_hoursN integerValue]==0&&[_minutesN integerValue]==0) {
        ALERTSHOW(@"有效期不能为0，请选择有效期");
        return;
    }
    
    if (_StrsurfaceT.length==0){
        _StrsurfaceT=@"";
    }
    if (_StrtoleranceT.length==0){
        _StrtoleranceT=@"";
    }
    if (_StrproducersL.length==0){
        _StrproducersL=@"不限";
    }
    if (_StrnumberCountT.length==0){
        _StrnumberCountT=@"";
    }
    
    if (_StrtotalCountT.length==0) {
         _StrtotalCountT=@"";
    }
    if (_Strnote.length==0) {
        _Strnote=@"";
    }
    NSString*keyTRADE_or_MATERIAL;//铝材页面代表牌号，其他页面代表材质
    NSString*toleranceT_or_NATIONAL;//铝材代表国标，其他代表公差
    NSDictionary*dic=[NSDictionary dictionary];
    if (lv_cai==YES) {
        keyTRADE_or_MATERIAL=@"TRADE_MARK";
        toleranceT_or_NATIONAL=@"NATIONAL_STANDARD";
        dic=@{@"VARIETY_ID":_classTypeN,keyTRADE_or_MATERIAL:_Strcai_zhiL,@"SURFACE_NAME":_StrsurfaceT,@"SPEC_CODE":_Strspecifications,@"MANUFACTURER_NAME":_StrproducersL,toleranceT_or_NATIONAL:_StrtoleranceT,@"WEIGHT":_StrtotalCountT,@"QUANTITY":_StrnumberCountT,@"REMARK":_Strnote,@"SUPPLY_PROVINCE_ID":_shengIDN,@"SUPPLY_CITY_ID":_cityIDN,@"EFFECTIVE_HOUR":_hoursN,@"EFFECTIVE_MINUTE":_minutesN,@"IS_NEED_INVOICE":_invoiceN,@"FREE_MODEL":_switchN,@"MATERIAL_NAME":@"",@"TOLERANCE":@""};
    }
    else{
        keyTRADE_or_MATERIAL=@"MATERIAL_NAME";
        toleranceT_or_NATIONAL=@"TOLERANCE";
        dic=@{@"VARIETY_ID":_classTypeN,keyTRADE_or_MATERIAL:_Strcai_zhiL,@"SURFACE_NAME":_StrsurfaceT,@"SPEC_CODE":_Strspecifications,@"MANUFACTURER_NAME":_StrproducersL,toleranceT_or_NATIONAL:_StrtoleranceT,@"WEIGHT":_StrtotalCountT,@"QUANTITY":_StrnumberCountT,@"REMARK":_Strnote,@"SUPPLY_PROVINCE_ID":_shengIDN,@"SUPPLY_CITY_ID":_cityIDN,@"EFFECTIVE_HOUR":_hoursN,@"EFFECTIVE_MINUTE":_minutesN,@"IS_NEED_INVOICE":_invoiceN,@"FREE_MODEL":_switchN};
    }
//    NSDictionary*dic=@{@"VARIETY_ID":_classTypeN,keyTRADE_or_MATERIAL:_Strcai_zhiL,@"SURFACE_NAME":_StrsurfaceT,@"SPEC_CODE":_Strspecifications,@"MANUFACTURER_NAME":_StrproducersL,toleranceT_or_NATIONAL:_StrtoleranceT,@"WEIGHT":_StrtotalCountT,@"QUANTITY":_StrnumberCountT,@"REMARK":_Strnote,@"SUPPLY_PROVINCE_ID":_shengIDN,@"SUPPLY_CITY_ID":_cityIDN,@"EFFECTIVE_HOUR":_hoursN,@"EFFECTIVE_MINUTE":_minutesN,@"IS_NEED_INVOICE":_invoiceN,@"FREE_MODEL":_switchN};
 
    [Controller upImgRequestWithUrl:@"AppPurchaseInfo/PostSavePurchaseInfo?from=app" parameters:dic imageDataAndUrl:_cImages finishBlock:^(ClassData *classData) {
        if ([classData.number integerValue]==0) {
            NSDictionary*dic=classData.data;
            IssueSuccess*issueSc=[[IssueSuccess alloc]initWithDic:dic];
            if ([issueSc.userScore integerValue]>0) {
                UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:issueSc.userScoreIncMsg delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                alertView.tag=100;
                [alertView show];
            }
            else{
                UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@"提示" message:@"发布成功" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
                alertView.tag=100;
                [alertView show];
            }
        }
        else{
            ALERTSHOW(classData.message);
        }

    }];
   
}
-(void)changeOFF
{
    _ISOFF=_off.on;
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==100) {
        UIAlertView*alertView2=[[UIAlertView alloc]initWithTitle:@"提示" message:@"恭喜你发布成功,你可以选择继续发布或者是查看询单" delegate:self cancelButtonTitle:@"查看询单" otherButtonTitles:@"继续发布",nil];
        alertView2.tag=200;
        [alertView2 show];
    }
    if (alertView.tag==200) {
        RootTabBarViewController *rootTabBarViewController = [RootTabBarViewController rootViewController];
        if (buttonIndex==0) {
            [rootTabBarViewController changeRootViewControllerTo:1];
        }
        if (buttonIndex==1) {
            [rootTabBarViewController changeRootViewControllerTo:2];
        }
    }

}

//点击按钮，拨打电话
-(void)callPhone
{
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850051"]]];
    [self.view addSubview:webview];
    //[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://4008850051"]];
}
//开始编辑时执行的方法
- (void)textFieldDidBeginEditing:(UITextField *)textField;
{
//    UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];

    switch (textField.tag) {
        case 190:
        {
            NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:1  inSection:1];
            [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        }
            break;
           
        case 191:
        {
            NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:2  inSection:1];
            [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        }
            break;
        case 193:
        {
            NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:4  inSection:1];
            [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        }
            break;
        case 194:
        {
            NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:0  inSection:2];
            [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        }
            break;
        case 291:
        {
            NSIndexPath*scrollTo=[NSIndexPath indexPathForRow:2  inSection:2];
            [_tableView scrollToRowAtIndexPath:scrollTo  atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
        }
            break;
        default:
            break;
    }
}
//编辑结束执行的方法
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    if (lv_cai==YES) {
        _Strcai_zhiL=_paiHao.text;
    }
    _StrthicknessT=_thicknessT.text;
    _StrwidthT=_widthT.text;
    _StrcT=_cT.text;
    _Strspecifications=_specifications.text;
    _StrsurfaceT=_surfaceT.text;
    _StrtoleranceT=_toleranceT.text;
    _StrtotalCountT=_totalCountT.text;
    _StrnumberCountT=_numberCountT.text;
    _Strnote=_note.text;
   
}
//键盘弹下
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}

- (void)disMiss {
    return;
}

- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
